/**
 * Created by JetBrains PhpStorm.
 * User: maplefalling
 * Date: 1/18/12
 * Time: 9:27 PM
 * To change this template use File | Settings | File Templates.
 */

Ext.ns('AAWE.App.List.Store');

Ext.define('AAWE.App.List.Store.CheckListStore',{
    extend:'Ext.data.Store',
    id : 'AAWE.App.List.Store.CheckListStore',
    autoload:true,
    autoSave:true,
    listeners:{
        datachanged:function(){
            this.save();
        }
    },
    getLists: function () {
        var _lists = [];
        for (i = 0; i < this.data.length; i++) {
            _lists.push(this.data.items[i].data);
        }
        return _lists;
    },
    getCount: function () {
        return this.data.length;
    },
    deleteList: function (id) {
        var _index = this.findExact('id', id);
        if (_index != -1) {
            this.removeAt(_index);
            this.sync();
        }
    },
    editName: function (id, name) {
        var _index = this.findExact('id', id);
        var _r;
        if (_index != -1) {
            _r = this.getAt(_index);
            _r.data.name = name;
            _r.setDirty();
            _r.save();
        }
        this.sync();
    }
});
